package com.goblin.model.uaa.repository;

import javax.persistence.EntityManager;

import com.goblin.common.response.PageHelper;
import com.goblin.common.response.Paged;
import com.goblin.model.base.BaseRepositoryImpl;
import com.goblin.model.uaa.po.Menu;
import com.goblin.model.uaa.po.QMenu;
import com.querydsl.core.QueryResults;
import com.querydsl.jpa.JPQLQuery;

public class MenuRepositoryImpl extends BaseRepositoryImpl<Menu, Integer>
		implements MenuRepositoryCustom {

	public MenuRepositoryImpl(EntityManager entityManager) {
		super(Menu.class, entityManager);
	}

	@Override
	public Paged<Menu> paged(PageHelper pageable) {
		JPQLQuery<Menu> query = this.jpaQueryFactory.selectFrom(QMenu.menu)
				.where(QMenu.menu.deleteTime.isNull()).orderBy(QMenu.menu.id.desc());
		query = (JPQLQuery<Menu>) getQuerydsl(pageable, query);
		QueryResults<Menu> results = query.fetchResults();
		return new Paged<Menu>(results.getTotal(), results.getResults());
	}
}
